package com.heu.blood.storge.controller;

import com.heu.blood.common.aop.ControllerLogAnnotation;
import com.heu.blood.common.utils.PageUtils;
import com.heu.blood.common.utils.R;
import com.heu.blood.storge.entity.BloodBackEntity;
import com.heu.blood.storge.service.BloodBackService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;


/**
 * 
 *
 * @author 
 * @email 
 * @date 2023-11-21 17:24:01
 */
@RestController
@RequestMapping("storge/bloodback")
public class BloodBackController {
    @Autowired
    private BloodBackService bloodBackService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @ControllerLogAnnotation(module = "血液退回", operate = "分页查询血液退回信息")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = bloodBackService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @ControllerLogAnnotation(module = "血液退回", operate = "根据id查询血液退回信息")
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		BloodBackEntity bloodBack = bloodBackService.getById(id);

        return R.ok().put("bloodBack", bloodBack);
    }

    /**
     * 保存
     */
    @ControllerLogAnnotation(module = "血液退回", operate = "插入血液退回信息")
    @RequestMapping("/save")
    public R save(@RequestBody BloodBackEntity bloodBack){
		bloodBackService.save(bloodBack);

        return R.ok();
    }

    /**
     * 修改
     */
    @ControllerLogAnnotation(module = "血液退回", operate = "更新血液退回信息")
    @RequestMapping("/update")
    public R update(@RequestBody BloodBackEntity bloodBack){
		bloodBackService.updateById(bloodBack);

        return R.ok();
    }

    /**
     * 删除
     */
    @ControllerLogAnnotation(module = "血液退回", operate = "根据id删除血液退回信息")
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids){
		bloodBackService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }
    /**
     * 单一的根据血液id修改退血表的退血原因
     */
    @ControllerLogAnnotation(module = "血液退回", operate = "根据血液id和退血原因查询血液退回信息")
    @RequestMapping("/simpleUpdateBloodBackReasonByBloodId")
    public R simpleUpdateBloodBackReasonByBloodId(@RequestParam("bloodId") String bloodId,@RequestParam("bloodBackReason") String bloodBackReason){
        bloodBackService.simpleUpdateBloodBackReasonByBloodId(bloodId,bloodBackReason);
        return R.ok();

    }

    /**
     * 根据血液id进行退血的操作
     */
    @ControllerLogAnnotation(module = "血液退回", operate = "根据血液id进行退血操作")
    @RequestMapping("/bloodBackByBloodId")
    public R bloodBackByBloodId(@RequestBody BloodBackEntity bloodBack){
        bloodBackService.bloodBackByBloodId(bloodBack);
        return R.ok();
    }


}
